import util from '../utils/util';

let eycService = {
    searchEycVehicleFileByUserId: function () {
        return util.promise('/searchEycVehicleFileByUserId');
    },
    getAccessToken: function () {
        return util.promise('/getAccessToken');
    },
    getYear: function (from, to) {
        let d = Math.abs(to.getTime() - from.getTime()) / 1000 / 24 / 60 / 60;
        return Math.floor(d / 365);//不整除
    },
    evaluatingPrice: function (vehicle) {
        let registerDt = vehicle.registerDt;
        let year = this.getYear(new Date(registerDt), new Date());
        let ratio = 1;
        if (year <= 1) {
            ratio = 0.9;
        }else if (year <= 2) {
            ratio = 0.8;
        } else if (year <= 3) {
            ratio = 0.7;
        } else if (year <= 4) {
            ratio = 0.61;
        } else if (year <= 5) {
            ratio = 0.52;
        } else if (year <= 6) {
            ratio = 0.44;
        } else if (year <= 7) {
            ratio = 0.36;
        }else if (year <= 8) {
            ratio = 0.29;
        }else if(year<=9){
            ratio=0.22;
        }else if(year<=10){
            ratio=0.15;
        }else if(year<=11){
            ratio=0.12;
        }else if(year<=12){
            ratio=0.1;
        }else if(year<=13){
            ratio=0.08;
        }else if(year<=14){
            ratio=0.07;
        }else if(year<=15){
            ratio=0.06;
        }else if(year>15){
            ratio=0.05;
        }
        let totalMileage = Math.floor(vehicle.totalMileage);
        if(totalMileage<=50000){
            ratio*=1;
        }else if(50000<totalMileage<=100000){
            ratio*=0.9;
        }else if(100000<totalMileage<=150000){
            ratio*=0.85;
        }else if(150000<totalMileage<=200000){
            ratio*=0.8;
        }else{
            ratio*=0.7;
        }

        let amount= Math.floor(Math.floor(vehicle.purchasePrice)*ratio*vehicle.vehicleCondRatio*vehicle.collisionRatio * vehicle.producerRatio);
        if(vehicle.skylight==='有'){
            amount+=500;
        }
        if(vehicle.leatherSeat==='有'){
            amount+=500;
        }
        if(vehicle.color==='黑' && vehicle.color==='白' && vehicle.color==='银色'){
            amount+=200;
        }
        if(vehicle.param1==='手动' ){
            amount-=1000;
        }
        if(vehicle.param2==='国六' ){
            amount+=500;
        }
        if(vehicle.param2==='国三及以下' ){
            amount-=1000;
        }
        if(vehicle.param3==='大于3.0' ){
            amount-=1000;
        }
        if(vehicle.param3==='小于1.2' ){
            amount-=500;
        }
        return amount;
    }


};
export default eycService;